/*
 * XMLStreamProvider.java
 *
 * Copyright 2011 Anish
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aosp.nanoxstream;

import java.util.Vector;

/**
 * <code>XMLStreamProvider.java</code>
 * <p>All classes that represents an XML data must implement {@link XMLStreamProvider}.</p>
 * @author Anish , anishkumar.ka@gmail.com
 * <dt><b>Date: </b><dd>Jan 5, 2011
 * <dt><b>Module: </b><dd>nanoxstream
 * <dt><b>Package: </b><dd>com.aosp.nanoxstream
 * <dt>TODO:<dd>
 */
public interface XMLStreamProvider {

	/**
	 * <h5>Implementation Sample</h5>
	 * <pre>
	 * <h6>Calling method</h6>
	 * <code>
	 * 	public static void main(String[] args) {
	 * 
	 * 		String testXml = "<sample>" +
	 * 		"<testName>Test Name</testName>" +
	 * 		"<testAddr>TVM</testAddr>"+
	 * 		"<childSample>" +
	 * 		"<childName>Child Name 1.1</childName>"+
	 * 		"<childName2>Child Name 1.2</childName2>"+
	 * 		"<childs>" +
	 * 		"<child>child 1</child>"+
	 * 		"<child>child 2</child>"+
	 * 		"</childs>"+
	 * 		"</childSample>"+
	 * 		"<childSample>" +
	 * 		"<childName>Child Name 2.1</childName>"+
	 * 		"<childName2>Child Name 2.2</childName2>"+
	 * 		"<childs>" +
	 * 		"<child>child 3</child>"+
	 * 		"<child>child 4</child>"+
	 * 		"</childs>"+
	 * 		"</childSample>"+
	 * 		"</sample>";
	 * 
	 * 		XMLStream xmlSteam = new XMLStream();
	 * 		xmlSteam.alias("sample", Sample.class);
	 * 		xmlSteam.alias("childSample", ChildSample.class);
	 * 		xmlSteam.alias("childs", Childs.class);
	 * 		xmlSteam.aliasField("childName", ChildSample.class, "childName1");
	 * 		xmlSteam.aliasField("child", Childs.class, "childs");
	 * 		xmlSteam.aliasField("child", Childs.class,String.class.getName());
	 * 		try {
	 * 			Sample sample = (Sample)xmlSteam.fromXML(testXml);
	 * 			System.out.println("sample.getTestName() : "+sample.getTestName());
	 * 			System.out.println("sample.getAddressName() : "+sample.getAddressName());
	 * 			System.out.println("sample.getChildSample().size : "+sample.getChildSample().size());
	 * 
	 * 			Enumeration enumeration = sample.getChildSample().elements();
	 * 			while (enumeration.hasMoreElements()) {
	 * 			ChildSample element = (ChildSample) enumeration.nextElement();
	 * 			System.out.println("Child  Name 1"+element.getChildName1());
	 * 			System.out.println("Child  Name 2"+element.getChildName2());
	 * 		}
	 * 		System.out.println("XML Obtained ........\n"+xmlSteam.toXml(sample));
	 * 		} catch (CannotResolveClassException e) {
	 * 			// TODO Auto-generated catch block
	 * 			e.printStackTrace();
	 * 		} catch (SecurityException e) {
	 * 			// TODO Auto-generated catch block
	 * 			e.printStackTrace();
	 * 		}
	 * }
	 *  </code>
	 * <h6>ChildSample class</h6>
	 * <code>
	 *  public class ChildSample implements XMLStreamProvider{
	 *  
	 *  private String childName1 = null;
	 *  
	 *  private String childName2 = null;
	 *  
	 *  private Childs childs = null;
	 *  
	 *  public ChildSample() {
	 *  }
	 *  
	 *  public String getChildName1() {
	 *  	return childName1;
	 *  }
	 *
	 *  public Object getFieldValue(String fieldName) {
	 *  	if(fieldName.equalsIgnoreCase("childName1")){
	 *  		return childName1;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childName2")){
	 *  		return childName2;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childs")){
	 *  		return childs;
	 *  	}
	 *  return null;
	 *  }
	 *  
	 *  public void setFieldValue(String fieldName, Object newValue) {
	 *  	if(fieldName.equalsIgnoreCase("childName1")){
	 *  		childName1=(String) newValue;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childName2")){
	 *  		childName2=(String) newValue;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childs")){
	 *  		childs=(Childs) newValue;
	 *  	}
	 *  }
	 *  
	 *  public String getChildName2() {
	 *  	return childName2;
	 *  }
	 *
	 *  public Vector getDeclaredFields() {
	 *  	Vector declaredFields = new Vector();
	 *  	declaredFields.addElement(new Field("childName1"));
	 *  	declaredFields.addElement(new Field("childName2"));
	 *  	declaredFields.addElement(new Field("childs"));
	 *  	return declaredFields;
	 *  }
	 *  }
	 *  </code>
	 *  <h6>Childs class</h6>
	 *  <code>
	 *  public class Childs implements XMLStreamProvider{
	 *  
	 *  private Vector childs = new Vector();
	 *  
	 *  public Childs() {
	 *  }
	 *
	 *  public Vector getDeclaredFields() {
	 *  	Vector fields = new Vector();
	 *  	fields.addElement(new Field("childs"));
	 *  	return fields;
	 *  }
	 *  
	 *  public Object getFieldValue(String fieldName) {
	 *  	if(fieldName.equalsIgnoreCase("childs"))
	 *  		return childs;
	 *  	return null;
	 *  }
	 *  
	 *  public void setFieldValue(String fieldName, Object newValue) {
	 *  	if(fieldName.equalsIgnoreCase("childs"))
	 *  		childs.addElement((String) newValue);
	 *  }
	 *  }
	 * </code>
	 * </pre>
	 * @param fieldName
	 * @return
	 */
	public Object getFieldValue(String fieldName);
	
	/**
	 * <h5>Implementation Sample</h5>
	 * <pre>
	 * <code>
	 *  <h6>Calling method</h6>
	 * 
	 * 	public static void main(String[] args) {
	 * 
	 * 		String testXml = "<sample>" +
	 * 		"<testName>Test Name</testName>" +
	 * 		"<testAddr>TVM</testAddr>"+
	 * 		"<childSample>" +
	 * 		"<childName>Child Name 1.1</childName>"+
	 * 		"<childName2>Child Name 1.2</childName2>"+
	 * 		"<childs>" +
	 * 		"<child>child 1</child>"+
	 * 		"<child>child 2</child>"+
	 * 		"</childs>"+
	 * 		"</childSample>"+
	 * 		"<childSample>" +
	 * 		"<childName>Child Name 2.1</childName>"+
	 * 		"<childName2>Child Name 2.2</childName2>"+
	 * 		"<childs>" +
	 * 		"<child>child 3</child>"+
	 * 		"<child>child 4</child>"+
	 * 		"</childs>"+
	 * 		"</childSample>"+
	 * 		"</sample>";
	 * 
	 * 		XMLStream xmlSteam = new XMLStream();
	 * 		xmlSteam.alias("sample", Sample.class);
	 * 		xmlSteam.alias("childSample", ChildSample.class);
	 * 		xmlSteam.alias("childs", Childs.class);
	 * 		xmlSteam.aliasField("childName", ChildSample.class, "childName1");
	 * 		xmlSteam.aliasField("child", Childs.class, "childs");
	 * 		xmlSteam.aliasField("child", Childs.class,String.class.getName());
	 * 		try {
	 * 			Sample sample = (Sample)xmlSteam.fromXML(testXml);
	 * 			System.out.println("sample.getTestName() : "+sample.getTestName());
	 * 			System.out.println("sample.getAddressName() : "+sample.getAddressName());
	 * 			System.out.println("sample.getChildSample().size : "+sample.getChildSample().size());
	 * 
	 * 			Enumeration enumeration = sample.getChildSample().elements();
	 * 			while (enumeration.hasMoreElements()) {
	 * 			ChildSample element = (ChildSample) enumeration.nextElement();
	 * 			System.out.println("Child  Name 1"+element.getChildName1());
	 * 			System.out.println("Child  Name 2"+element.getChildName2());
	 * 		}
	 * 		System.out.println("XML Obtained ........\n"+xmlSteam.toXml(sample));
	 * 		} catch (CannotResolveClassException e) {
	 * 			// TODO Auto-generated catch block
	 * 			e.printStackTrace();
	 * 		} catch (SecurityException e) {
	 * 			// TODO Auto-generated catch block
	 * 			e.printStackTrace();
	 * 		}
	 * }
	 * 
	 * <h6>ChildSample class</h6>
	 *  public class ChildSample implements XMLStreamProvider{
	 *  
	 *  private String childName1 = null;
	 *  
	 *  private String childName2 = null;
	 *  
	 *  private Childs childs = null;
	 *  
	 *  public ChildSample() {
	 *  }
	 *  
	 *  public String getChildName1() {
	 *  	return childName1;
	 *  }
	 *
	 *  public Object getFieldValue(String fieldName) {
	 *  	if(fieldName.equalsIgnoreCase("childName1")){
	 *  		return childName1;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childName2")){
	 *  		return childName2;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childs")){
	 *  		return childs;
	 *  	}
	 *  return null;
	 *  }
	 *  
	 *  public void setFieldValue(String fieldName, Object newValue) {
	 *  	if(fieldName.equalsIgnoreCase("childName1")){
	 *  		childName1=(String) newValue;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childName2")){
	 *  		childName2=(String) newValue;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childs")){
	 *  		childs=(Childs) newValue;
	 *  	}
	 *  }
	 *  
	 *  public String getChildName2() {
	 *  	return childName2;
	 *  }
	 *
	 *  public Vector getDeclaredFields() {
	 *  	Vector declaredFields = new Vector();
	 *  	declaredFields.addElement(new Field("childName1"));
	 *  	declaredFields.addElement(new Field("childName2"));
	 *  	declaredFields.addElement(new Field("childs"));
	 *  	return declaredFields;
	 *  }
	 *  }
	 *  
	 *  <h6>Childs class</h6>
	 *  public class Childs implements XMLStreamProvider{
	 *  
	 *  private Vector childs = new Vector();
	 *  
	 *  public Childs() {
	 *  }
	 *
	 *  public Vector getDeclaredFields() {
	 *  	Vector fields = new Vector();
	 *  	fields.addElement(new Field("childs"));
	 *  	return fields;
	 *  }
	 *  
	 *  public Object getFieldValue(String fieldName) {
	 *  	if(fieldName.equalsIgnoreCase("childs"))
	 *  		return childs;
	 *  	return null;
	 *  }
	 *  
	 *  public void setFieldValue(String fieldName, Object newValue) {
	 *  	if(fieldName.equalsIgnoreCase("childs"))
	 *  		childs.addElement((String) newValue);
	 *  }
	 *  }
	 * </code>
	 * </pre>
	 * @param fieldName
	 * @param newValue
	 */
	public void setFieldValue(String fieldName,Object newValue);
	
	/**
	 * <h5>Implementation Sample</h5>
	 * <pre>
	 * <code>
	 * <h6>Calling method</h6>
	 * 
	 * 	public static void main(String[] args) {
	 * 
	 * 		String testXml = "<sample>" +
	 * 		"<testName>Test Name</testName>" +
	 * 		"<testAddr>TVM</testAddr>"+
	 * 		"<childSample>" +
	 * 		"<childName>Child Name 1.1</childName>"+
	 * 		"<childName2>Child Name 1.2</childName2>"+
	 * 		"<childs>" +
	 * 		"<child>child 1</child>"+
	 * 		"<child>child 2</child>"+
	 * 		"</childs>"+
	 * 		"</childSample>"+
	 * 		"<childSample>" +
	 * 		"<childName>Child Name 2.1</childName>"+
	 * 		"<childName2>Child Name 2.2</childName2>"+
	 * 		"<childs>" +
	 * 		"<child>child 3</child>"+
	 * 		"<child>child 4</child>"+
	 * 		"</childs>"+
	 * 		"</childSample>"+
	 * 		"</sample>";
	 * 
	 * 		XMLStream xmlSteam = new XMLStream();
	 * 		xmlSteam.alias("sample", Sample.class);
	 * 		xmlSteam.alias("childSample", ChildSample.class);
	 * 		xmlSteam.alias("childs", Childs.class);
	 * 		xmlSteam.aliasField("childName", ChildSample.class, "childName1");
	 * 		xmlSteam.aliasField("child", Childs.class, "childs");
	 * 		xmlSteam.aliasField("child", Childs.class,String.class.getName());
	 * 		try {
	 * 			Sample sample = (Sample)xmlSteam.fromXML(testXml);
	 * 			System.out.println("sample.getTestName() : "+sample.getTestName());
	 * 			System.out.println("sample.getAddressName() : "+sample.getAddressName());
	 * 			System.out.println("sample.getChildSample().size : "+sample.getChildSample().size());
	 * 
	 * 			Enumeration enumeration = sample.getChildSample().elements();
	 * 			while (enumeration.hasMoreElements()) {
	 * 			ChildSample element = (ChildSample) enumeration.nextElement();
	 * 			System.out.println("Child  Name 1"+element.getChildName1());
	 * 			System.out.println("Child  Name 2"+element.getChildName2());
	 * 		}
	 * 		System.out.println("XML Obtained ........\n"+xmlSteam.toXml(sample));
	 * 		} catch (CannotResolveClassException e) {
	 * 			// TODO Auto-generated catch block
	 * 			e.printStackTrace();
	 * 		} catch (SecurityException e) {
	 * 			// TODO Auto-generated catch block
	 * 			e.printStackTrace();
	 * 		}
	 * }
	 * 
	 * <h6>ChildSample class</h6>
	 *  public class ChildSample implements XMLStreamProvider{
	 *  
	 *  private String childName1 = null;
	 *  
	 *  private String childName2 = null;
	 *  
	 *  private Childs childs = null;
	 *  
	 *  public ChildSample() {
	 *  }
	 *  
	 *  public String getChildName1() {
	 *  	return childName1;
	 *  }
	 *
	 *  public Object getFieldValue(String fieldName) {
	 *  	if(fieldName.equalsIgnoreCase("childName1")){
	 *  		return childName1;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childName2")){
	 *  		return childName2;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childs")){
	 *  		return childs;
	 *  	}
	 *  return null;
	 *  }
	 *  
	 *  public void setFieldValue(String fieldName, Object newValue) {
	 *  	if(fieldName.equalsIgnoreCase("childName1")){
	 *  		childName1=(String) newValue;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childName2")){
	 *  		childName2=(String) newValue;
	 *  	}
	 *  	if(fieldName.equalsIgnoreCase("childs")){
	 *  		childs=(Childs) newValue;
	 *  	}
	 *  }
	 *  
	 *  public String getChildName2() {
	 *  	return childName2;
	 *  }
	 *
	 *  public Vector getDeclaredFields() {
	 *  	Vector declaredFields = new Vector();
	 *  	declaredFields.addElement(new Field("childName1"));
	 *  	declaredFields.addElement(new Field("childName2"));
	 *  	declaredFields.addElement(new Field("childs"));
	 *  	return declaredFields;
	 *  }
	 *  }
	 *  
	 *  <h6>Childs class</h6>
	 *  public class Childs implements XMLStreamProvider{
	 *  
	 *  private Vector childs = new Vector();
	 *  
	 *  public Childs() {
	 *  }
	 *
	 *  public Vector getDeclaredFields() {
	 *  	Vector fields = new Vector();
	 *  	fields.addElement(new Field("childs"));
	 *  	return fields;
	 *  }
	 *  
	 *  public Object getFieldValue(String fieldName) {
	 *  	if(fieldName.equalsIgnoreCase("childs"))
	 *  		return childs;
	 *  	return null;
	 *  }
	 *  
	 *  public void setFieldValue(String fieldName, Object newValue) {
	 *  	if(fieldName.equalsIgnoreCase("childs"))
	 *  		childs.addElement((String) newValue);
	 *  }
	 *  }
	 * </code>
	 * </pre>
	 * @return
	 */
	public Vector getDeclaredFields();
	
}
